package com.padakeji.android.ui.examples;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.padakeji.android.ui.widget.FullyGridLayoutManager;
import com.padakeji.android.ui.widget.GridSpacingItemDecoration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by atanl on 2015/12/8.
 */
public class FullGridTestActivity extends Activity {

    private RecyclerView recyclerView;

    private void findViews() {
        recyclerView = (RecyclerView) findViewById(R.id.activity_fullyGridTest_recycler);
    }

    private List<String> data = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullygrid_test);

        findViews();

        configViews();

    }

    private void configViews() {
        data.addAll(Arrays.asList("abc", "bcd", "cdf", "cdf", "cdf", "cdf", "cdf"));
        recyclerView.addItemDecoration(new GridSpacingItemDecoration(3, 30, true));
        RecyclerView.LayoutManager layout = new FullyGridLayoutManager(this, 3);
        recyclerView.setLayoutManager(layout);
        recyclerView.setAdapter(new RecyclerView.Adapter() {
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                ImageView image = new ImageView(FullGridTestActivity.this);
                RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                image.setLayoutParams(params);
                image.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher));
                image.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_light));
                ViewHolder vh = new ViewHolder(image);
                return vh;
            }

            @Override
            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            }

            @Override
            public int getItemCount() {
                return data.size();
            }
        });

    }

    private class ViewHolder extends RecyclerView.ViewHolder {

        public ViewHolder(View itemView) {
            super(itemView);
        }
    }

}
